package com.cn.crmsystem.service.systemService.impl;

import com.cn.crmsystem.mapper.systemMapper.NoticeMapper;
import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.Notice;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.pojo.User;
import com.cn.crmsystem.service.systemService.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class NoticeServiceImpl implements NoticeService{

    @Autowired
    private NoticeMapper noticeMapper;

    public ResultJson selectNotice(Notice notice){
        List<Notice> list = noticeMapper.selectNotice(notice);
        if (list != null && list.size() > 0){
            return new ResultJson().getSuccess("查询成功",list);
        }
        return new ResultJson().getFail("查询失败");
    }

    @Override
    public ResultJson addNotice(Notice notice, Login login) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("notice",notice);
        map.put("login",login);
        if (noticeMapper.addNotice(map) > 0) {
            return new ResultJson().getSuccess("新增成功");
        }
        return new ResultJson().getFail("新增失败");
    }

    @Override
    public ResultJson deleteNotice(Integer id) {
        int rows = noticeMapper.deleteNotice(id);
        if (rows > 0){
            return new ResultJson().getSuccess("删除成功");
        }
        return new ResultJson().getFail("删除失败");
    }

    @Override
    public ResultJson updateNotice(Notice notice, Login login) {
        HashMap<Object,Object> map = new HashMap<>();
        map.put("notice",notice);
        map.put("login",login);
        if (noticeMapper.updateNotice(map) > 0){
            return new ResultJson().getSuccess("修改成功");
        }
        return new ResultJson().getFail("修改失败");
    }

    @Override
    public ResultJson deleteManyNotice(Integer[] ids) {
        int result=0;
        for(int i=0;i<ids.length;i++){
            result=noticeMapper.deleteNotice(ids[i]);
        }
        if(result>0){
            return new ResultJson<>().getSuccess("删除成功");
        }else{
            return new ResultJson<>().getFail("删除失败");
        }
    }
}
